﻿<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:z="#RowsetSchema">

	<xsl:key name="pages" match="Page" use="substring(@DateTime,1,4)"/>

	<xsl:template match="/">

		<link rel="stylesheet" type="text/css" href="/Style Library/EnhancedCQWP/Css/Rollups.css" title="Style">
			<xsl:comment>Comment added so script is recognised</xsl:comment>
		</link>
		
		<script src="/Style Library/EnhancedCQWP/Javascript/LimitTo10.js">
			<xsl:comment>Comment added so script is recognised</xsl:comment>
		</script>

		<div class="ECRollup">
			<ul class="ECGroup">

				<xsl:if test="count(/Pages/Page) = 0">
					<div>
						Momenteel geen publicaties.
					</div>
				</xsl:if>

				<xsl:for-each select="/Pages/Page[generate-id() = generate-id(key('pages',substring(@DateTime,1,4))[1])]">
					<xsl:sort select="substring(@DateTime,1,4)" order="descending"/>
					<xsl:variable name="publishedYear" select="substring(@DateTime,1,4)" />
					<xsl:variable name="yearToExpand" select="/Pages/@ExpandParam" />

					<li>
						<h2>
							<a>
								<xsl:attribute name="href">
									<xsl:text>?expandParam=</xsl:text>
									<xsl:value-of select="$publishedYear"/>
								</xsl:attribute>
								<xsl:value-of select="$publishedYear"/>
								<xsl:text> (</xsl:text>
								<xsl:value-of select="count(/Pages/Page[substring(@DateTime,1,4)=$publishedYear])"/>
								<xsl:text> items)</xsl:text>
							</a>
						</h2>

						<xsl:if test="$publishedYear = $yearToExpand or (position() = 1 and $yearToExpand = '')">
							<ul class="pages">
								<xsl:for-each select="/Pages/Page[substring(@DateTime,1,4)=$publishedYear]">
									<xsl:sort select="@DateTime" order="descending"/>
									<li>
										<span class="pageTitle">
											<a class="rolluplink">
												<xsl:attribute name="href">
													<xsl:value-of select="@AbsolutePath"/>
												</xsl:attribute>
												<span>
													<xsl:value-of select="normalize-space(@Title)"/>
												</span>
											</a>
										</span>
										<span class="pubDateTime">
											<xsl:value-of select="ddwrt:FormatDateTime(string(@DateTime) ,1043,'d MMMM yyyy')"/>
										</span>
									</li>
								</xsl:for-each>
							</ul>
							<a class="showRemainingPages" href="#" style="display: none;">
								Meer &gt;&gt;
							</a>
							<a class="hideRemainingPages" href="#" style="display: none;">
								&lt;&lt; Minder
							</a>
						</xsl:if>
					</li>
				</xsl:for-each>
			</ul>
		</div>
	</xsl:template>
</xsl:stylesheet>
